﻿{% extends "base.html" %}

{% block scripts %}
{% endblock %}

{% block content %}
    <h1>Заказы</h1>
    <div class="user_cabinet_base">
        <div class="panel_1">
            <ul class="profile_options">
                <li class="option_item"><a href="/add_order/"> Разместить заказ</a></li>
            </ul>
        </div>
    </div>

    {% if orders.object_list %}
        <ul class="paging">
            {% if orders.has_previous %}
                <li class="item"><a href="/orders/{{ orders.previous_page_number }}/"><img class="icon" src="/media/images/icon_arrow_2.gif" width="11" height="5"></a></li>
            {% endif %}

            {% for page in orders.paginator.page_range %}
                {% if page == orders.number %}
                    <li class="item item_current">{{ page }}</li>
                {% else %}
                    <li class="item"> <a href="/orders/{{ page }}/">{{ page }}</a></li>
                {% endif %}
            {% endfor %}

            {% if orders.has_next %}
                <li class="item"><a href="/orders/{{ orders.next_page_number }}/"><img class="icon" src="/media/images/icon_arrow_1.gif" width="11" height="5"></a></li>
            {% endif %}
        </ul>
    {% endif %}

    <ul class="order_list">
        {% for order in orders.object_list %}
        {% if order.active %}
        <li class="list_item{% if forloop.first %} list_item_first{% endif %}">
            <h2 class="block_header">
                <a href="/order/{{ order.id }}/">{{ order.subj }}</a>
                <span class="price">
                {% if order.price %}{{ order.price }}р{% endif %}
                </span>

            </h2>
            <p>{{ order.text|linebreaksbr }}</p>
            <ul class="options">
                {% if order.user == request.user %}
                    <li class="item"><a href="/edit_order/{{ order.id }}/">Редактировать</a></li>
                {% endif %}
                {% if request.user.companies.count > 0 %}
                    <li class="item"><a href="/response_to_order/{{ order.id }}/">Ответить на заказ ({{ order.responses.count }})<span class="info"></span></a></li>
                {% else %}
                <li class="item">Чтобы ответить на заказ<a href="/register_company/">зарегистрируйте компанию<span class="info"></span></a></li>
                {% endif %}

            </ul>
        </li>
        {% else %}
            {% if order.user == request.user %}
                <li class="list_item{% if forloop.first %} list_item_first{% endif %}">
                    <h2 class="block_header">
                        <a href="/order/{{ order.id }}/">{{ order.subj }}</a>
                        <span class="price">
                        {% if order.price %}{{ order.price }}р{% endif %}
                        </span>
                    </h2>
                    <p>{{ order.text|linebreaksbr }}</p>
                    <ul class="options">
                        {% if order.user == request.user %}
                        <li class="item"><a href="/edit_order/{{ order.id }}/">Редактировать</a></li>
                        {% endif %}
                        <li class="item">Заказ неактивен <span class="info"></span></li>
                    </ul>
                </li>
            {% endif %}
        {% endif %}
        {% endfor %}
    </ul>

    {% if orders.object_list %}
        <ul class="paging">
            {% if orders.has_previous %}
                <li class="item"><a href="/orders/{{ orders.previous_page_number }}/"><img class="icon" src="/media/images/icon_arrow_2.gif" width="11" height="5"></a></li>
            {% endif %}

            {% for page in orders.paginator.page_range %}
                {% if page == orders.number %}
                    <li class="item item_current">{{ page }}</li>
                {% else %}
                    <li class="item"> <a href="/orders/{{ page }}/">{{ page }}</a></li>
                {% endif %}
            {% endfor %}

            {% if orders.has_next %}
                <li class="item"><a href="/orders/{{ orders.next_page_number }}/"><img class="icon" src="/media/images/icon_arrow_1.gif" width="11" height="5"></a></li>
            {% endif %}
        </ul>
    {% endif %}
{% endblock %}